package com.ljh.mybatis.controller;


import com.github.pagehelper.PageInfo;
import com.ljh.mybatis.entity.Department;
import com.ljh.mybatis.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Department)表控制层
 *
 * @author makejava
 * @since 2020-11-09 19:03:45
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Autowired
    private DepartmentService departmentService;
   //通过id查询单条数据
    @GetMapping("/getUserById")
    public Department selectOne(@PathVariable("id") Integer id) {
        return this.departmentService.queryById(id);
    }
    //查询所有数据
    @GetMapping("/selectAll")
    public List<Department> selectAll(){
        return this.departmentService.selectAll();
    }
    //根据id删除单个数据
    @DeleteMapping("/deleteUserById/{id}")
    public boolean deleteUserById(@PathVariable Integer id){
        return this.departmentService.deleteUserById(id);
    }
    //根据ids删除多个数据
    @DeleteMapping("deleteUserByIds/{ids}")
    public boolean deleteUserByIds(@PathVariable Integer[] ids){
        return this.departmentService.deleteUserByIds(ids);
    }
    //新增
    @PostMapping("/addUser")
    public boolean addUser(@RequestBody Department department){
        return this.departmentService.addUser(department);
    }
    //根据id更新
    @PostMapping("updateById")
    public boolean updateById(@RequestBody Department department){
        return this.departmentService.updateById(department);
    }
    //多表联合查询
    @GetMapping("selectMore")
    public List<Department> selectMore(){
        return this.departmentService.selectMore();
    }
    //使用PagerHelper完成分页查询
    @GetMapping("/pageListDep")
    public PageInfo<Department> pageListDep(@RequestParam(value = "当前页码",required = true) int page,
                                            @RequestParam(value = "每页数量",required = true) int limit){
          return  departmentService.pageListDep(page,limit);
    }
    /**
     * 根据条件查询 动态sql(if)
     */
    @GetMapping("getDepCondition")
    public List<Department> getDepCondition( Department department){
        return departmentService.getDepCondition(department);
    }

}